<?php

/**
 * This is the model class for table "account_token".
 *
 * The followings are the available columns in table 'account_token':
 * @property integer $token_id
 * @property integer $uid
 * @property string $createTime
 * @property string $ipv4
 * @property string $expireTime
 * @property string $token
 * @property string $expireTimeText
 *
 * The followings are the available model relations:
 * @property Account $u
 */
class AccountToken extends ActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AccountToken the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'account_token';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('uid', 'numerical', 'integerOnly'=>true),
			array('ipv4', 'length', 'max'=>45),
			array('token', 'length', 'max'=>255),
			array('expireTimeText', 'length', 'max'=>50),
			array('createTime, expireTime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('token_id, uid, createTime, ipv4, expireTime, token, expireTimeText', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'u' => array(self::BELONGS_TO, 'Account', 'uid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'token_id' => 'Token',
			'uid' => 'Uid',
			'createTime' => 'Create Time',
			'ipv4' => 'Ipv4',
			'expireTime' => 'Expire Time',
			'token' => 'Token',
			'expireTimeText' => 'Expire Time Text',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('token_id',$this->token_id);
		$criteria->compare('uid',$this->uid);
		$criteria->compare('createTime',$this->createTime,true);
		$criteria->compare('ipv4',$this->ipv4,true);
		$criteria->compare('expireTime',$this->expireTime,true);
		$criteria->compare('token',$this->token,true);
		$criteria->compare('expireTimeText',$this->expireTimeText,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}